<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Web App打包工具</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #1a2a6c, #b21f1f, #1a2a6c);
            color: #fff;
            min-height: 100vh;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        
        .container {
            max-width: 1200px;
            width: 100%;
            margin: 0 auto;
        }
        
        header {
            text-align: center;
            padding: 30px 0;
            margin-bottom: 30px;
        }
        
        h1 {
            font-size: 2.8rem;
            margin-bottom: 10px;
            text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
            background: linear-gradient(to right, #ff8a00, #da1b60);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        .subtitle {
            font-size: 1.2rem;
            opacity: 0.9;
            max-width: 700px;
            margin: 0 auto;
            line-height: 1.6;
        }
        
        .app-container {
            display: flex;
            flex-wrap: wrap;
            gap: 30px;
            margin-bottom: 40px;
        }
        
        .upload-section, .preview-section, .settings-section {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }
        
        .upload-section {
            flex: 1;
            min-width: 300px;
        }
        
        .preview-section {
            flex: 1;
            min-width: 300px;
            display: flex;
            flex-direction: column;
        }
        
        .settings-section {
            flex: 100%;
            margin-top: 20px;
        }
        
        .section-title {
            font-size: 1.5rem;
            margin-bottom: 20px;
            display: flex;
            align-items: center;
            gap: 10px;
            color: #ff8a00;
        }
        
        .section-title i {
            font-size: 1.8rem;
        }
        
        .drop-area {
            border: 3px dashed rgba(255, 255, 255, 0.4);
            border-radius: 15px;
            padding: 40px 20px;
            text-align: center;
            cursor: pointer;
            transition: all 0.3s ease;
            background: rgba(0, 0, 0, 0.2);
        }
        
        .drop-area:hover {
            background: rgba(0, 0, 0, 0.3);
            border-color: #ff8a00;
        }
        
        .drop-area i {
            font-size: 4rem;
            margin-bottom: 20px;
            color: #ff8a00;
        }
        
        .drop-area h3 {
            font-size: 1.5rem;
            margin-bottom: 10px;
        }
        
        .drop-area p {
            opacity: 0.8;
            margin-bottom: 20px;
        }
        
        .btn {
            background: linear-gradient(45deg, #ff8a00, #da1b60);
            color: white;
            border: none;
            padding: 12px 30px;
            font-size: 1rem;
            border-radius: 50px;
            cursor: pointer;
            transition: all 0.3s ease;
            font-weight: bold;
            display: inline-flex;
            align-items: center;
            gap: 8px;
            box-shadow: 0 4px 15px rgba(218, 27, 96, 0.4);
        }
        
        .btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 20px rgba(218, 27, 96, 0.6);
        }
        
        .btn:active {
            transform: translateY(1px);
        }
        
        .btn-secondary {
            background: rgba(255, 255, 255, 0.15);
        }
        
        .btn-secondary:hover {
            background: rgba(255, 255, 255, 0.25);
        }
        
        #fileInput {
            display: none;
        }
        
        .preview-container {
            flex-grow: 1;
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 10px;
            overflow: hidden;
            background: white;
            position: relative;
            min-height: 300px;
        }
        
        .preview-phone {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 280px;
            height: 500px;
            border: 10px solid #333;
            border-radius: 30px;
            background: #f0f0f0;
            box-shadow: 0 15px 50px rgba(0, 0, 0, 0.5);
            overflow: hidden;
        }
        
        .phone-content {
            width: 100%;
            height: 100%;
            overflow: auto;
            color: #333;
            padding: 20px;
        }
        
        .phone-content h2 {
            color: #da1b60;
            margin-bottom: 15px;
        }
        
        .phone-content p {
            line-height: 1.6;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
        }
        
        input, select {
            width: 100%;
            padding: 12px 15px;
            border-radius: 8px;
            border: 1px solid rgba(255, 255, 255, 0.3);
            background: rgba(0, 0, 0, 0.2);
            color: white;
            font-size: 1rem;
        }
        
        input:focus {
            outline: none;
            border-color: #ff8a00;
        }
        
        .settings-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
        }
        
        .actions {
            display: flex;
            gap: 15px;
            margin-top: 30px;
            flex-wrap: wrap;
        }
        
        .file-info {
            margin-top: 20px;
            padding: 15px;
            background: rgba(0, 0, 0, 0.2);
            border-radius: 10px;
            display: none;
        }
        
        .file-info.active {
            display: block;
        }
        
        .file-info p {
            margin: 5px 0;
        }
        
        .status {
            padding: 20px;
            text-align: center;
            margin-top: 20px;
            border-radius: 10px;
            display: none;
        }
        
        .status.success {
            background: rgba(46, 204, 113, 0.2);
            border: 1px solid #2ecc71;
            display: block;
        }
        
        .status.error {
            background: rgba(231, 76, 60, 0.2);
            border: 1px solid #e74c3c;
            display: block;
        }
        
        footer {
            text-align: center;
            padding: 30px 0;
            margin-top: auto;
            opacity: 0.7;
            font-size: 0.9rem;
        }
        
        .features {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
            margin: 30px 0;
        }
        
        .feature-card {
            background: rgba(255, 255, 255, 0.05);
            padding: 20px;
            border-radius: 15px;
            text-align: center;
            transition: transform 0.3s ease;
        }
        
        .feature-card:hover {
            transform: translateY(-5px);
            background: rgba(255, 255, 255, 0.1);
        }
        
        .feature-card i {
            font-size: 2.5rem;
            color: #ff8a00;
            margin-bottom: 15px;
        }
        
        .feature-card h3 {
            font-size: 1.3rem;
            margin-bottom: 10px;
        }
        
        @media (max-width: 768px) {
            .app-container {
                flex-direction: column;
            }
            
            .preview-phone {
                width: 250px;
                height: 450px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>Web App 打包工具</h1>
            <p class="subtitle">将您的HTML应用转换为可安装的PWA（渐进式Web应用），无需服务器支持，完全在浏览器中完成</p>
        </header>
        
        <div class="features">
            <div class="feature-card">
                <i class="fas fa-mobile-alt"></i>
                <h3>移动设备支持</h3>
                <p>创建适配各种移动设备的应用程序</p>
            </div>
            <div class="feature-card">
                <i class="fas fa-bolt"></i>
                <h3>快速打包</h3>
                <p>几秒钟内将HTML转换为应用</p>
            </div>
            <div class="feature-card">
                <i class="fas fa-lock"></i>
                <h3>无需服务器</h3>
                <p>所有操作在浏览器中完成，保护隐私</p>
            </div>
            <div class="feature-card">
                <i class="fas fa-cloud-download-alt"></i>
                <h3>离线功能</h3>
                <p>生成支持离线使用的应用</p>
            </div>
        </div>
        
        <div class="app-container">
            <div class="upload-section">
                <h2 class="section-title"><i class="fas fa-cloud-upload-alt"></i>上传HTML文件</h2>
                <div class="drop-area" id="dropArea">
                    <i class="fas fa-file-code"></i>
                    <h3>拖放HTML文件到此处</h3>
                    <p>或点击按钮选择文件</p>
                    <button class="btn" id="selectFileBtn"><i class="fas fa-folder-open"></i> 选择HTML文件</button>
                    <input type="file" id="fileInput" accept=".html">
                </div>
                
                <div class="file-info" id="fileInfo">
                    <p><strong>文件名:</strong> <span id="fileName">-</span></p>
                    <p><strong>文件大小:</strong> <span id="fileSize">-</span></p>
                    <p><strong>最后修改:</strong> <span id="fileModified">-</span></p>
                </div>
            </div>
            
            <div class="preview-section">
                <h2 class="section-title"><i class="fas fa-mobile-alt"></i>应用预览</h2>
                <div class="preview-container">
                    <div class="preview-phone">
                        <div class="phone-content" id="previewContent">
                            <h2>您的应用预览</h2>
                            <p>上传HTML文件后，此处将显示您的应用预览效果。</p>
                            <p>您可以通过右侧的设置自定义应用名称、图标和主题颜色。</p>
                            <div style="margin-top: 20px; padding: 15px; background: #e0f7fa; border-radius: 10px;">
                                <h3>示例内容</h3>
                                <p>这是一个简单的预览展示。您的实际应用内容将在此处显示。</p>
                                <button style="background: #ff8a00; color: white; border: none; padding: 8px 16px; border-radius: 5px; margin-top: 10px;">示例按钮</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="settings-section">
                <h2 class="section-title"><i class="fas fa-cog"></i>应用设置</h2>
                <div class="settings-grid">
                    <div class="form-group">
                        <label for="appName">应用名称</label>
                        <input type="text" id="appName" placeholder="输入应用名称" value="我的Web应用">
                    </div>
                    
                    <div class="form-group">
                        <label for="shortName">简称</label>
                        <input type="text" id="shortName" placeholder="输入简称" value="WebApp">
                    </div>
                    
                    <div class="form-group">
                        <label for="themeColor">主题颜色</label>
                        <input type="color" id="themeColor" value="#ff8a00">
                    </div>
                    
                    <div class="form-group">
                        <label for="bgColor">背景颜色</label>
                        <input type="color" id="bgColor" value="#1a2a6c">
                    </div>
                    
                    <div class="form-group">
                        <label for="displayMode">显示模式</label>
                        <select id="displayMode">
                            <option value="standalone">独立应用</option>
                            <option value="fullscreen">全屏</option>
                            <option value="minimal-ui">最小UI</option>
                            <option value="browser">浏览器</option>
                        </select>
                    </div>
                    
                    <div class="form-group">
                        <label for="orientation">屏幕方向</label>
                        <select id="orientation">
                            <option value="any">任意方向</option>
                            <option value="portrait">竖屏</option>
                            <option value="landscape">横屏</option>
                        </select>
                    </div>
                </div>
                
                <div class="actions">
                    <button class="btn" id="generateBtn"><i class="fas fa-cogs"></i> 生成应用</button>
                    <button class="btn btn-secondary" id="downloadBtn" disabled><i class="fas fa-download"></i> 下载应用包</button>
                    <button class="btn btn-secondary" id="installBtn" disabled><i class="fas fa-mobile-alt"></i> 安装到设备</button>
                    <button class="btn btn-secondary" id="resetBtn"><i class="fas fa-redo"></i> 重置</button>
                </div>
                
                <div class="status" id="statusMessage"></div>
            </div>
        </div>
        
        <footer>
            <p>© 2023 Web App打包工具 | 此工具完全在浏览器中运行，无需服务器支持 | 生成的应用不需要签名</p>
        </footer>
    </div>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const dropArea = document.getElementById('dropArea');
            const fileInput = document.getElementById('fileInput');
            const selectFileBtn = document.getElementById('selectFileBtn');
            const fileInfo = document.getElementById('fileInfo');
            const fileName = document.getElementById('fileName');
            const fileSize = document.getElementById('fileSize');
            const fileModified = document.getElementById('fileModified');
            const previewContent = document.getElementById('previewContent');
            const generateBtn = document.getElementById('generateBtn');
            const downloadBtn = document.getElementById('downloadBtn');
            const installBtn = document.getElementById('installBtn');
            const resetBtn = document.getElementById('resetBtn');
            const statusMessage = document.getElementById('statusMessage');
            
            let uploadedFile = null;
            
            // 选择文件按钮
            selectFileBtn.addEventListener('click', () => {
                fileInput.click();
            });
            
            // 文件输入变化
            fileInput.addEventListener('change', handleFileSelect);
            
            // 拖放功能
            ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
                dropArea.addEventListener(eventName, preventDefaults, false);
            });
            
            function preventDefaults(e) {
                e.preventDefault();
                e.stopPropagation();
            }
            
            ['dragenter', 'dragover'].forEach(eventName => {
                dropArea.addEventListener(eventName, highlight, false);
            });
            
            ['dragleave', 'drop'].forEach(eventName => {
                dropArea.addEventListener(eventName, unhighlight, false);
            });
            
            function highlight() {
                dropArea.style.borderColor = '#ff8a00';
                dropArea.style.backgroundColor = 'rgba(0, 0, 0, 0.4)';
            }
            
            function unhighlight() {
                dropArea.style.borderColor = 'rgba(255, 255, 255, 0.4)';
                dropArea.style.backgroundColor = 'rgba(0, 0, 0, 0.2)';
            }
            
            // 处理文件拖放
            dropArea.addEventListener('drop', handleDrop, false);
            
            function handleDrop(e) {
                const dt = e.dataTransfer;
                const file = dt.files[0];
                handleFile(file);
            }
            
            function handleFileSelect(e) {
                const file = e.target.files[0];
                handleFile(file);
            }
            
            function handleFile(file) {
                if (file && file.type === 'text/html') {
                    uploadedFile = file;
                    
                    // 显示文件信息
                    fileName.textContent = file.name;
                    fileSize.textContent = formatFileSize(file.size);
                    fileModified.textContent = new Date(file.lastModified).toLocaleString();
                    fileInfo.classList.add('active');
                    
                    // 预览文件内容
                    const reader = new FileReader();
                    reader.onload = function(e) {
                        previewContent.innerHTML = e.target.result;
                    };
                    reader.readAsText(file);
                    
                    showStatus('文件上传成功！', 'success');
                } else {
                    showStatus('请上传有效的HTML文件', 'error');
                }
            }
            
            function formatFileSize(bytes) {
                if (bytes === 0) return '0 Bytes';
                const k = 1024;
                const sizes = ['Bytes', 'KB', 'MB', 'GB'];
                const i = Math.floor(Math.log(bytes) / Math.log(k));
                return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
            }
            
            // 生成应用
            generateBtn.addEventListener('click', function() {
                if (!uploadedFile) {
                    showStatus('请先上传HTML文件', 'error');
                    return;
                }
                
                // 模拟生成过程
                showStatus('正在生成应用包...', 'success');
                
                setTimeout(() => {
                    downloadBtn.disabled = false;
                    installBtn.disabled = false;
                    showStatus('应用生成成功！您现在可以下载或安装应用。', 'success');
                }, 2000);
            });
            
            // 下载应用包
            downloadBtn.addEventListener('click', function() {
                if (!uploadedFile) return;
                
                // 创建下载链接
                const reader = new FileReader();
                reader.onload = function(e) {
                    const content = e.target.result;
                    
                    // 创建Blob对象
                    const blob = new Blob([content], {type: 'text/html'});
                    const url = URL.createObjectURL(blob);
                    
                    // 创建下载链接
                    const a = document.createElement('a');
                    a.href = url;
                    a.download = uploadedFile.name.replace('.html', '_app.html');
                    document.body.appendChild(a);
                    a.click();
                    
                    // 清理
                    setTimeout(() => {
                        document.body.removeChild(a);
                        window.URL.revokeObjectURL(url);
                    }, 100);
                };
                
                reader.readAsText(uploadedFile);
                
                showStatus('应用下载已开始...', 'success');
            });
            
            // 安装应用
            installBtn.addEventListener('click', function() {
                showStatus('此功能需要浏览器支持PWA安装。在支持的环境中，此操作将触发应用安装流程。', 'success');
                
                // 在实际应用中，这里会包含PWA安装逻辑
                // 由于安全限制，需要HTTPS环境才能安装PWA
            });
            
            // 重置按钮
            resetBtn.addEventListener('click', function() {
                fileInput.value = '';
                uploadedFile = null;
                fileInfo.classList.remove('active');
                previewContent.innerHTML = `
                    <h2>您的应用预览</h2>
                    <p>上传HTML文件后，此处将显示您的应用预览效果。</p>
                    <p>您可以通过右侧的设置自定义应用名称、图标和主题颜色。</p>
                    <div style="margin-top: 20px; padding: 15px; background: #e0f7fa; border-radius: 10px;">
                        <h3>示例内容</h3>
                        <p>这是一个简单的预览展示。您的实际应用内容将在此处显示。</p>
                        <button style="background: #ff8a00; color: white; border: none; padding: 8px 16px; border-radius: 5px; margin-top: 10px;">示例按钮</button>
                    </div>
                `;
                downloadBtn.disabled = true;
                installBtn.disabled = true;
                statusMessage.className = 'status';
                
                // 重置表单
                document.getElementById('appName').value = '我的Web应用';
                document.getElementById('shortName').value = 'WebApp';
                document.getElementById('themeColor').value = '#ff8a00';
                document.getElementById('bgColor').value = '#1a2a6c';
                document.getElementById('displayMode').value = 'standalone';
                document.getElementById('orientation').value = 'any';
                
                showStatus('已重置所有设置', 'success');
                setTimeout(() => {
                    statusMessage.className = 'status';
                }, 2000);
            });
            
            function showStatus(message, type) {
                statusMessage.textContent = message;
                statusMessage.className = `status ${type}`;
            }
        });
    </script>
</body>
</html>